﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DebugTools
{
    public class Ininfo
    {
        public string _sPath { set; get; }
        public string _sAddressPSU { set; get; }
        public string _sAddressEEP { set; get; }
        public string _sTypeI2CIO { set; get; }
        public string _sPortCom { set; get; }
        public bool _bDataSave { set; get; }
        public int _nTypeDataSave { set; get; }
        public string _sPassword { set; get; }
        public string _sRev { set; get; }
        public string _sModelName { set; get; }
        public int _nFrequencyI2C { set; get; }
        public bool _bUnlockSupport { set; get; }
        public int _nlevel_TXT_DataSave { set; get; }
        public int _nlevel_HEX_DataSave { set; get; }
        public int _nlevel_BIN_DataSave { set; get; }
        public bool _bSN_Warning_Duplicate { set; get; }
        public bool _bReadOrWrite { set; get; }
        public bool _bMesEnable { set; get; }
        public bool _bClearBlockBoxEnable { set; get; }
        public bool _bAutoExit { set; get; }
        public int _nTargetProgress { set; get; }

        public Ininfo(string Path)
        {
            _sPath = Path;
            IniFiles iniFile = new IniFiles(_sPath);
            _sAddressPSU = iniFile.ReadString("General", "Slave_Address", "B2"); 
            _sAddressEEP = iniFile.ReadString("General", "P/S Address", "A2");
            _sTypeI2CIO = iniFile.ReadString("General", "I2C_Interface", "MCP");
            _sPortCom = iniFile.ReadString("General", "COM_PORT", "COM1");
            _bDataSave = iniFile.ReadBool("General", "Save Data", true);
            _sPassword = iniFile.ReadString("General", "Pass Word", "0000");
            _sRev = iniFile.ReadString("General", "Rev", "xxx");
            _sModelName = iniFile.ReadString("General", "Model Name", "U1A-D10800-DRB");
            _nTypeDataSave = iniFile.ReadInteger("General", "Save Data Type", 0);
            _nFrequencyI2C = iniFile.ReadInteger("General", "USBI2C_Frequency", 100);
            _bUnlockSupport = iniFile.ReadBool("General", "UnlockSupport", true);
            _nlevel_TXT_DataSave = iniFile.ReadInteger("General", "Save TXT Data", 1);
            _nlevel_HEX_DataSave = iniFile.ReadInteger("General", "Save HEX Data", 1);
            _nlevel_BIN_DataSave = iniFile.ReadInteger("General", "Save BIN Data", 1);
            _bSN_Warning_Duplicate = iniFile.ReadBool("General", "SN Duplicate Warning", false);
            _bReadOrWrite = iniFile.ReadBool("General", "WriteOrRead", true);
            _bMesEnable = iniFile.ReadBool("General", "MesEnable", true);
            _bClearBlockBoxEnable = iniFile.ReadBool("General", "ClearBlackBoxEnable", true);
            _bAutoExit = iniFile.ReadBool("General", "AutoExit", false);
            _nTargetProgress = 40;
        }

        public void Save()
        {
            IniFiles iniFile = new IniFiles(Form_Main.ininfo._sPath);
            iniFile.WriteString("General", "Slave_Address", _sAddressPSU);
            iniFile.WriteString("General", "P/S Address", _sAddressEEP);
            iniFile.WriteString("General", "I2C_Interface", _sTypeI2CIO);
            iniFile.WriteString("General", "COM_PORT", _sPortCom);
            iniFile.WriteBool("General", "Save Data", _bDataSave);
            iniFile.WriteString("General", "Pass Word", _sPassword);
            iniFile.WriteString("General", "Rev", _sRev);
            iniFile.WriteString("General", "Label File Name", _sModelName);
            iniFile.WriteInteger("General", "Save Data Type", _nTypeDataSave);
            iniFile.WriteInteger("General", "USBI2C_Frequency", _nFrequencyI2C);
            iniFile.WriteBool("General", "UnlockSupport", _bUnlockSupport);
            iniFile.WriteInteger("General", "Save TXT Data", _nlevel_TXT_DataSave);
            iniFile.WriteInteger("General", "Save HEX Data", _nlevel_HEX_DataSave);
            iniFile.WriteInteger("General", "Save BIN Data", _nlevel_BIN_DataSave);
            iniFile.WriteBool("General", "SN Duplicate Warning", _bSN_Warning_Duplicate);
            iniFile.WriteBool("General", "WriteOrRead", _bReadOrWrite);
            iniFile.WriteBool("General", "MesEnable", _bMesEnable);
            iniFile.WriteBool("General", "ClearBlackBoxEnable", _bClearBlockBoxEnable);
            iniFile.WriteBool("General", "AutoExit", _bAutoExit);
        }
    }
}
